package com.regedit.aplicacion.activities;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.regedit.aplicacion.R;

public class MiMapaActivity extends FragmentActivity {

	private GoogleMap mMap;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.mi_mapa);
		mMap = ((SupportMapFragment) getSupportFragmentManager()
				.findFragmentById(R.id.map)).getMap();

		// mMap.setMyLocationEnabled(true);

		// Sacar ubicacion por GPS
		final LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
		final Criteria criteria = new Criteria();
		final String provider = service.getBestProvider(criteria, false);
		final Location location = service.getLastKnownLocation(provider);

		// Ubicacion en el mapa con las coordenadas
		final LatLng userLocation = new LatLng(location.getLatitude(),
				location.getLongitude());
		mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 13));
		if (mMap != null) {
			insertarLocacionesEnMapa();
		}
	}

	private void insertarLocacionesEnMapa() {
		mMap.addMarker(new MarkerOptions()
				.position(new LatLng(-12.07705, -77.03626))
				.icon(BitmapDescriptorFactory
						.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
				.title("Sise").snippet("Instituto Sise"));
	}
}
